﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//引入命名空间
using stwh_Model;
using stwh_BLL;
using stwh_Common;
using Newtonsoft.Json;
using stwh_Web.Handler.stwh_admin;
using System.Web.SessionState;
using System.Text;

namespace stwh_Web.Handler.extend.huodong
{
    /// <summary>
    /// login 的摘要说明
    /// </summary>
    public class login : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            try
            {
                if (context.Request.HttpMethod.ToLower() == "post")
                {
                    string username = context.Request["name"];
                    if (string.IsNullOrEmpty(username))
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "请输入用户名！", 0);
                        return;
                    }
                    string pwd = context.Request["pwd"];
                    if (string.IsNullOrEmpty(pwd))
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "请输入密码！", 0);
                        return;
                    }
                    if (username == "bsswkj" && pwd == "+bsswkj888")
                    {
                        context.Session["cjuser"] = "cjuser";
                        //获取今日参与抽奖的用户数据（并且没有被抽到过）
                        List<stwh_cjtel> ListData = new stwh_cjtelBLL().GetModelList("CONVERT(varchar(300),stwh_cjaddtime,120) like '" + DateTime.Now.ToString("yyyy-MM-dd") + "%' and stwh_cjmobile not in (select stwh_cjrmobile from stwh_cjresult) order by stwh_cjid desc");
                        StringBuilder sb = new StringBuilder();
                        foreach (stwh_cjtel item in ListData)
                        {
                            sb.Append(item.stwh_cjmobile + ",");
                        }
                        BaseHandler.SendResponseMsgs(context, "0", sb.ToString().Substring(0, sb.ToString().Length - 1), 0);
                    }
                    else
                    {
                        BaseHandler.SendResponseMsgs(context, "-1", "用户名或密码错误！", 0);
                    }
                }
                else BaseHandler.SendResponseMsgs(context, "-1", "数据传输方法错误，请采用post方式！", 0);
            }
            catch (Exception)
            {
                BaseHandler.SendResponseMsgs(context, "-1", "服务器异常，请稍后再试！", 0);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}